<template>
  <view>
    <view class="noticeBar">
      <uni-notice-bar show-icon show-close scrollable text="要省钱，上优购！低价好货不用凑！优购在手，天下我有！犹豫一秒，价格溜走！今天优购不下单，明天原价泪汪汪！" />
    </view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="item in swiperList" :key="item.goods_id">
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <view class="nav">
      <view v-for="(item, index) in navList" :key="index" @click="navClickHandler(item.name)">
        <image class="nav-img" :src="item.image_src"></image>
      </view>
    </view>
    <view class="floor" v-for="(item, index) in floorList" :key="index">
      <view class="floor-top">
        <image :src="item.floor_title.image_src" mode=""></image>
      </view>
      <view class="floor-bottom">
        <navigator :url="item.product_list[0].url" class="floor-bottom-left">
          <image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
        </navigator>
        <view class="floor-bottom-right"> 
          <navigator :url="item1.url" class="floor-bottom-right-box" v-for="(item1, i) in item.product_list" :key="i" v-if="i !== 0">
            <image  :style="{width: item1.image_width + 'rpx'}" :src="item1.image_src" mode="widthFix"></image>
          </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import badge from '@/mixins/tabbar-badge.js'
  export default {
    mixins: [badge],
    data() {
      return {
        swiperList: [],
        navList: [],
        floorList: []
      };
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods: {
      async getSwiperList() {
        const { data: { message } } = await uni.$http.get('/api/public/v1/home/swiperdata')
        this.swiperList = message
      },
      async getNavList() {
        const { data: { message } } = await uni.$http.get('/api/public/v1/home/catitems')
        this.navList = message
      },
      navClickHandler(value){
        if(value === '分类'){
          uni.switchTab({ url: '/pages/cate/cate' })
        }
      },
      async getFloorList(){
          const { data: { message } } = await uni.$http.get('/api/public/v1/home/floordata')
          message.forEach(item => {
            item.product_list.forEach(i => {
              i.url = '/subpkg/goods_list/goods_list?' + i.navigator_url.split('?')[1]
            })
          })
          this.floorList = message
        },
        gotoSearch(){
          uni.navigateTo({
            url: '/subpkg/goods_search/goods_search'
          })
        },
      }
    }
</script>

<style lang="scss">
  .noticeBar {
    position: sticky;
    top: 0;
    z-index: 999;
  }
  swiper {
    height: 330rpx;
    .swiper-item,
    image {
     width: 100%;
     height: 100%;
    }
  }
  .nav{
    margin: 30rpx 0;
    display: flex;
    justify-content: space-around;
    .nav-img{
        width: 128rpx;
        height: 140rpx;
      }
  }
  .floor{
    image{
      border-radius: 20rpx;
    }
    .floor-top{
      image{
        width: 100%;
        height: 60rpx;
      }
    }
    .floor-bottom{
      margin: 0 10rpx;
      display: flex;
      .floor-bottom-left{
        margin-right: 15rpx;
      }
      .floor-bottom-right{
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
      }
    }
  }
</style>